#ifndef DDCP_ITEM_HPP__
#define DDCP_ITEM_HPP__

#include <list>
#include <stdint.h>
#include "tinyxml/tinyxml.h"
#include "DDCPItemTypes.hpp"


class CDDCPHandleEmpty;
class CDDCPItemHandle;

/**
 *  class: 
 *  purpose: 
 *  brief: 
 *
 *  details: 
 */
class CDDCPItemAbstractCheck{
public:
    virtual bool operator()( CDDCPItemHandle& handle ) = 0;
};


/**
 *  class: 
 *  purpose: 
 *  brief: 
 *
 *  details: 
 */
class CDDCPItemHandle
{
public:
    virtual CDDCPItemHandle addItem( const char* itmName, uint32_t length ) = 0;

    virtual CDDCPItemHandle addItem( CDDCPItemTypes::EDDCPType type );    

    virtual CDDCPItemHandle itemDo( const char* itmName, uint32_t length ) = 0;

    virtual CDDCPItemHandle itemDo( CDDCPItemTypes::EDDCPType type );

    virtual CDDCPItemHandle child() = 0;

    virtual CDDCPItemHandle item( const char* itmName, uint32_t length ) = 0; 

    virtual CDDCPItemHandle item( CDDCPItemTypes::EDDCPType type );

    virtual bool isElement(){return false;}

    virtual bool isMessage(){return false;}

    virtual bool isEmpty(){return true;}

    virtual const char* getValue( const char* name ) = 0;

    virtual const char* getText() = 0;

    //virtual TiXmlNode* getItem() = 0;

    virtual void itemList( const char * type, uint32_t length, std::list<CDDCPItemHandle>&typelist ) = 0;

    virtual void itemList( CDDCPItemTypes::EDDCPType type, std::list<CDDCPItemHandle>& typelist );
    
    virtual void setText(const char* text, uint32_t lenth) = 0;

    //virtual void setValue(const char* text, uint32_t lenth) = 0;
    virtual void operator=(CDDCPItemHandle& oth) = 0;

public:

    //static CDDCPHandleEmpty Empty;
};


/**
 *  class: 
 *  purpose: 
 *  brief: 
 *
 *  details: 
 */
class CDDCPHandleEmpty: public CDDCPItemHandle{

    virtual CDDCPItemHandle addItem( const char* itmName, uint32_t length ){return *this;}

    virtual CDDCPItemHandle itemDo( const char* itmName, uint32_t length ){return *this;}

    virtual CDDCPItemHandle child(){return *this;}

    virtual CDDCPItemHandle item( const char* itmName, uint32_t length ){return *this;}

    //virtual TiXmlNode* getItem(){return NULL;}

    virtual const char* getValue( const char* name ){return "";}

    virtual const char* getText(){return "";}

    virtual void itemList( const char * type, uint32_t length, std::list<CDDCPItemHandle>&typelist ){}

    virtual void setText(const char* text){}

    virtual void operator=(CDDCPItemHandle& oth){return oth;}
};

extern CDDCPHandleEmpty DDCPEmpty;

/**
 *  class: 
 *  purpose: 
 *  brief: 
 *
 *  details: 
 */
class CDDCPItem: public CDDCPItemHandle
{
public:
#ifdef _DEBUG
    //friend class CDDCPItemTest;
#endif
    
    CDDCPItem( TiXmlNode& node );

    virtual ~CDDCPItem();

    ////////////////////////////////CDDCPItemHandle Methos/////////////////////////////////////

    virtual CDDCPItemHandle addItem( const char* itmName, uint32_t length );

    virtual CDDCPItemHandle itemDo( const char* itmName, uint32_t length );

    virtual CDDCPItemHandle child();

    virtual CDDCPItemHandle item( const char* itmName, uint32_t length );

    virtual bool isElement();

    virtual bool isEmpty();

    virtual const char* getValue( const char* name ) ;

    virtual const char* getText() ;

    virtual void itemList( const char * type, uint32_t length, std::list<CDDCPItemHandle>&typelist );

    virtual void setText( const char* text );

    ///////////////////////////////////////////////////////////////////////////////////////////

    CDDCPItem* firstChild( const char* name, uint32_t length );

    CDDCPItem* nextChild();

    bool delChild( const char* name, uint32_t length );

    //bool delChild( CDDCPItem* itm );

protected:

    //virtual TiXmlNode* getItem();

    //virtual CDDCPItemHandle* findChild( TiXmlNode* node );


protected:

    TiXmlNode& m_node;

    TiXmlNode* m_curChild;
    
    //std::list<CDDCPItemHandle*> m_items;

};



#endif

